//
//  XGYXViewController.m
//  uplife
//
//  Created by ZhangCheng on 2019/8/16.
//  Copyright © 2019 ZhangCheng. All rights reserved.
//

#import "XGYXViewController.h"

@interface XGYXViewController ()
@property(nonatomic,weak)IBOutlet UIView *tfSuperView1;
@property(nonatomic,weak)IBOutlet UITextField *oldPWDTF;
@property(nonatomic,weak)IBOutlet UIView *confirmView;

@end

@implementation XGYXViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tfSuperView1.layer setBorderColor:[UIColor colorWithRed:203.0f/255.0f green:172.0f/255.0f blue:116.0f/255.0f alpha:1.0f].CGColor];

    // Do any additional setup after loading the view.
}
-(BOOL)canSendRequestForUpdateMail{
    BOOL result = YES;
    NSString *code = [self.oldPWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if (code.length==0) {
        [SVProgressHUD showErrorWithStatus:@"请输入新邮箱地址"];
        result = NO;
        return result;
    }else if ([[ZCTool sharedInstance]isValidateEmail:code]==NO){
        [SVProgressHUD showErrorWithStatus:@"请输入正确的邮箱地址"];
        result = NO;
        return result;
    }
    return result;
}
-(IBAction)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)submitAction{
    if ([self canSendRequestForUpdateMail]) {
        NSString *code = [self.oldPWDTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        NSString *urlString = [NSString stringWithFormat:@"%@/user/modifyEmail.do",JSXF_HOST];
        NSDictionary *params = @{
                                 @"email":code
                                 };
        
        [SVProgressHUD show];
        
        [ZCWebServiceHelper requestWithMethod:POST andUrlStr:urlString andParameters:params andFinished:^(id response, NSURLSessionDataTask *dataTask) {
            [SVProgressHUD showSuccessWithStatus:response[@"message"]];
            self.confirmView.hidden = NO;
        }];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
